package com.kyivmohyla.kma2.dao.mapper;

import com.kyivmohyla.kma2.model.History;
import org.springframework.jdbc.core.ResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;

class HistoryResultSetExtractor implements ResultSetExtractor<History> {

    @Override
    public History extractData(ResultSet resultSet) throws SQLException {
        History history = new History();
        try {
            history.setHistoryId(resultSet.getInt("history_id"));
            history.setNewState(resultSet.getInt("new_state"));
            history.setChangeDate(resultSet.getTimestamp("change_date"));
            history.setCommentary(resultSet.getString("commentary"));
            history.setOrderId(resultSet.getInt("order_id"));
            history.setStaffId(resultSet.getInt("staff_id"));
            history.setNewStateName(resultSet.getString("new_state_name"));
            history.setStaffName(resultSet.getString("staff_name"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return history;
    }

}